package com.xm.xmapp.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.TextView;

import com.xm.xmapp.R;

public class CustomTextView extends TextView {

	private int tipVisibility = 0;

	public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(attrs);
	}

	public CustomTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(attrs);
	}

	public CustomTextView(Context context) {
		super(context);

	}

	public void init(AttributeSet attrs) {
		if (attrs != null) {
			TypedArray array = getContext().obtainStyledAttributes(attrs,
					R.styleable.RedTipTextView);
			tipVisibility = array.getInt(
					R.styleable.RedTipTextView_redTipsVisibility, 0);
			array.recycle();
		}
	}

	public enum InnerStatus {
		VISIBLE, GONE
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		if (tipVisibility == 1) {
			int width = getWidth();
			int paddingRight = getPaddingRight();
			int paddingTop = getPaddingTop();
			Paint paint = new Paint();
			paint.setColor(Color.RED);
			paint.setAntiAlias(true);
			paint.setDither(true);
			paint.setStyle(Style.FILL_AND_STROKE);
			canvas.drawCircle(width - getPaddingRight() / 2, paddingTop * 2,
					paddingRight / 4, paint);
		}
		
	}

	public void setVisibility(InnerStatus visibility) {
		if (visibility == InnerStatus.VISIBLE)
			tipVisibility = 1;
		else
			tipVisibility = 0;
		invalidate();
	}
}